package com.lzh.others.java8.lamda;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test2_2 {
    public static void main(String[] args) {
//        Runnable noArguments = () -> {
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            System.out.println("Hello World1");
//        };
        Runnable noArguments1 = new Runnable() {
            @Override
            public void run() {

            }
        };

//        noArguments.run();
//        ActionListener oneArguments = event -> System.out.println("button clicked");
//        Runnable MultipleArguments = () -> {
//            System.out.println("Hello World2");
//            System.out.println("Hello World3");
//        };
//        MultipleArguments.run();
//        new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("noArguments = " + noArguments);
//
//            }
//        }.run();

        BinaryOperator<Long> add = (Long x, Long y) -> x + y;//表示这个段代码，指代这个函数(方法)
        Long apply = add.apply(1L, 2L);//调用这个方法
        System.out.println("apply = " + apply);
        BinaryOperator<Integer> maxBy = BinaryOperator.maxBy((x, y) -> x >= y ? 1 : -1);
        Integer apply1 = maxBy.apply(50, 120);
        System.out.println("apply1 = " + apply1);

        List<String> list = new ArrayList<>();
        list.add("A");
        list.add("A");
        list.add("A");
        list.add("B");
        long count = list.stream().filter(item -> {
            System.out.println("item = " + item);
            return "A".equals(item);
        }).count();
        System.out.println("count = " + count);

        List<Integer> collect = Stream.of("a", "b", "c", "hello")
                .map(item -> 1)
                .collect(Collectors.toList());
        collect.forEach(item -> System.out.println(item.toString()));
//        assertEqu


    }
}
